package com.flower.handle.exception;

import com.flower.domain.ApiResult;
import com.flower.enums.ApiCode;
import lombok.extern.slf4j.Slf4j;
import org.omg.CORBA.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 运行时的异常
     * @param e
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public ApiResult systemExceptionHandler(RuntimeException e) {
        //打印异常信息
        log.error("出现了异常！{}", e.getMessage());
        //从异常对象中获取提示信息封装返回
        return ApiResult.fail(e.getMessage());
    }

    /**
     * 全局异常
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public ApiResult ExceptionHandler(Exception e) {
        //打印异常信息
        log.error("出现了异常！{}", e.getMessage());
        //从异常对象中获取提示信息封装返回
        return ApiResult.fail(e.getMessage());
    }


}
